using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace com.yoozoo.gta.Art.RpgScene
{
    //作用：为解决IOS设备上GTA世界里豪车试驾活动中CheckPoint的光圈特效材质引用丢失问题，预先收集好特效预制体的材质后面再赋回去。
    public class CustomSetMaterial : MonoBehaviour
    {
        [SerializeField]private List<Material> cacheMaterials = new List<Material>();
        [SerializeField]private List<Renderer> cacheMeshRender = new List<Renderer>();

        private void Start()
        {
            for (int i = 0; i < cacheMeshRender.Count; i++)
            {
                cacheMeshRender[i].sharedMaterial = cacheMaterials[i];
            }
        }
#if UNITY_EDITOR
        public void GetMaterials()
        {
            cacheMaterials.Clear();
            cacheMeshRender.Clear();
            Renderer[] renderer = this.GetComponentsInChildren<Renderer>();
            for (int i = 0; i < renderer.Length; i++)
            {
                cacheMaterials.Add(renderer[i].sharedMaterial);
                cacheMeshRender.Add(renderer[i]);
            }
        }
#endif
    }
}